package com.yanqu.road.utils.serialize;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class StringToListListInt extends JsonDeserializer<List<List<Integer>>> {

    @Override
    public List<List<Integer>> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        String text = jsonParser.getText();
        String[] split1 = text.split("\\|");
        List<List<Integer>> list = new ArrayList<>();
        for (String s1 : split1) {
            String[] split2 = s1.split(";");
            List<Integer> list1 = new ArrayList<>();
            for (String s2 : split2) {
                list1.add(Integer.parseInt(s2));
            }
            list.add(list1);
        }
        return list;
    }
}
